function courseCreate(courseId) {
    var data = new FormData();
    data.append("otherId", courseId);
    data.append("orderType", "COURSE");
    data.append("payType", "WXPAY");
    return orderCreate(data);
}

function documentCreate(documentId) {
    var data = new FormData();
    data.append("otherId", documentId);
    data.append("orderType", "DOCUMENT");
    data.append("payType", "WXPAY");
    return orderCreate(data);
}

function orderCreate(data) {
    axios.post('/order/create.json', data).then(function (json) {
        if (json.data.code === 0) {
            //判断是否扣款完成
            if (json.data.msg === 'complete') {
                parent.location.reload();
            } else {
                setInterval("checkPayed('" + json.data.data.orderNo + "')", 5000);
                if (json.data.data.payChannel === "H5") {
                    parent.location.href = json.data.data.payUrl;
                } else {
                    if (parent){
                        parent.toWxJSAPI(json.data.data);
                    }else {
                        toWxJSAPI(json.data.data);
                    }
                }
            }
        } else {
            layer.msg('支付失败，' + json.data.msg);
        }
    }).catch(function (error) {
        layer.msg(error);
    });
}

function orderRepay(orderId, payType) {
    if (!payType) payType = "WXPAY";
    var data = new FormData();
    data.append("orderId", orderId);
    data.append("payType", payType);
    axios.post('/order/repay.json', data).then(function (json) {
        if (json.data.code === 0) {
            //判断是否扣款完成
            if (json.data.msg === 'complete') {
                parent.location.reload();
            } else {
                setInterval("checkPayed('" + json.data.data.orderNo + "')", 5000);
                if (json.data.data.payChannel === "H5") {
                    parent.location.href = json.data.data.payUrl;
                } else {
                    if (parent) {
                        parent.toWxJSAPI(json.data.data);
                    } else {
                        toWxJSAPI(json.data.data);
                    }
                }
            }
        } else {
            layer.msg('支付失败，' + json.data.msg);
        }
    }).catch(function (error) {
        layer.msg(error);
    });
}
//检查订单是否支付成功
function checkPayed(orderNo) {
    axios.post('/order/pay/check.json', {"orderNo": orderNo}).then(function (json) {
        if (json.data.code === 0) {
            return layer.msg("订单支付成功，正在刷新页面...", {icon: 1, time: 500}, function () {
                parent.location.reload();
            });
        }
    });
}